<?php

if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * 分页类 扩展
 * 扩展方法 http://codeigniter.org.cn/user_guide/general/creating_libraries.html
 */

class MY_Pagination extends CI_Pagination
{
	//以下参数设置主要是为了结合pw90的UI分页样式而做的调正
	public $use_page_numbers = true; //启用后显示的是当前页码
	public $num_links = 3; //左右的数字
	public $first_link = '首'; //首页文字
	public $last_link = '尾'; //尾页文字
	public $page_query_string = true; //启用查询字符串，而不是URI段
	public $query_string_segment = 'page'; //传递页数的查询字符串
	public $full_tag_open = '<div class="pages">'; //封装标签开始
	public $full_tag_close = '</div>'; //封装标签结束
	public $prev_link = '上'; //上一页文字
	public $next_link = '下'; //下一页文字

    /*
	public function __construct($params = array())
	{
		parent::__construct($params);
	}
    */

	/**
	 * 获取limit的查询起始数
	 */
	public function get_offset($page = NULL)
	{
		$page = intval($page);

		//总页数
		$total_page = ceil($this->total_rows / $this->per_page);

		//当前页数
		$page > $total_page && $page = $total_page;
		($page <= 0 || !is_numeric($page)) && $page = 1;

        $CI =& get_instance();
        $CI->config->item('enable_query_strings') === FALSE && $this->cur_page = $page;

		//起始数
		$offset = ($page - 1) * $this->per_page;
		return $offset;
	}
}

/* End of file MY_Pagination.php */
/* Location: ./application/library/MY_Pagination.php */
